package com.menggudf.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.menggudf.model.ResultModel;
import com.menggudf.model.SystemAdminModel;
import com.menggudf.service.DiagnosisService;
import com.menggudf.service.IllnessService;

@Controller
@RequestMapping("illOper")
public class IllOperController {
    
    @Autowired
    private IllnessService illnessService;
    
    @Autowired
    private DiagnosisService diagnosisService;
    
    /**
     * 根据疾病id获取疾病
     * */
    @RequestMapping("deleteIll")
    @ResponseBody
    public ResultModel deleteIll(
            @RequestParam("illness") String illness,
            HttpSession httpSession){      
            return illnessService.deleteIll(illness);
        
    }
    
    @RequestMapping("deleteSymptom")
    @ResponseBody
    public ResultModel deleteSymptom(
            @RequestParam("illness") String illness,
            HttpSession httpSession){
        
        SystemAdminModel model = (SystemAdminModel) httpSession.getAttribute("SystemAdminModel");
        if(model==null || model.getFlag()!=1){
            return ResultModel.fail("没有权限", null);
        }else{
            return illnessService.deleteSymptom(illness);
        }
        
    }
    
    @RequestMapping("deleteParts")
    @ResponseBody
    public ResultModel deleteParts(
            @RequestParam("illness") String illness,
            HttpSession httpSession){
        
        SystemAdminModel model = (SystemAdminModel) httpSession.getAttribute("SystemAdminModel");
        if(model==null || model.getFlag()!=1){
            return ResultModel.fail("没有权限", null);
        }else{
            return illnessService.deleteParts(illness);
        }
        
    }
    
    //获取ids的辅助检查
    @RequestMapping("getExamByillList")
    @ResponseBody
    public List<String> getExamByillList(
            @RequestParam("ids") String ids){
                return illnessService.getExamByillList(ids);
        
    }
    
    /**
     * excel导入
     * @throws IOException 
     * */
    @RequestMapping("importExcel")
    @ResponseBody
    public ResultModel importExcel(
            @RequestParam MultipartFile file,
            HttpServletRequest request, HttpServletResponse response,HttpSession httpSession) throws IOException{
        SystemAdminModel model = (SystemAdminModel) httpSession.getAttribute("SystemAdminModel");
        if(model==null){
            return ResultModel.fail("会话过期，请重新登录", null);
        }
        return illnessService.importExcel(file,model.getAdminCode());
         
    }
}
